<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>表单输入提示的实现 未完成</title>
</head>
<body>
<script type="text/javascript">
    var xmlobj;
    //创建ActiveXObject 对象 XMLHTTPRequest对象
    function CreateXMLHTTPRequest(){
        if(window.ActionXObject){
            xmlobj = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            xmlobj = new XMLHttpRequest();
        }
    }

    function searchCity(){
        CreateXMLHTTPRequest();
        xmlobj.open("GET","city.xml",true);
        xmlobj.onreadystatechange = StatHandler;
        xmlobj.send(null);
    }

    function StatHandler(){
        var city = document.getElementById('city');
        var popup = document.getElementById('popup');
        if(document.getElementById('city').value != ""){
            var xml = xmlobj.responseXML;
            var array_city = xml.getElementsByTagName("city");

            popup.innerHTML = "";
            for(i=0;i<array_city.length;i++){
                var city_name = array_city[i].childNodes[0].nodeValue;
                if(city_name.substr(0,city.value.length) == city.values)
                    popup.innerHTML += city_name + "<br />";
            }
        }else{
            popup.innerHTML = "";
        }
    }
</script>
<div>
    Search:<input type="text" size="20" id="city" onkeyup="searchCity()" style="
    height: 20" />
</div>
<div style="position: absolute;left:75px;width: 200px;border: 1px solid;" id="popup">

</div>
</body>
</html>